<?php

namespace App\Repositories\Eloquent;

use Prettus\Repository\Eloquent\BaseRepository;
use App\Contracts\Repositories\NewsCategoryRepository;
use App\Models\NewsCategory;

/**
 * Class NewsCategoryRepositoryEloquent
 * @package namespace App\Repositories\Eloquent;
 */
class NewsCategoryRepositoryEloquent extends BaseRepository implements NewsCategoryRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return NewsCategory::class;
    }

    public function sort(&$rows, $parent_id = 0,$level=0)
    {
        static $data = [];
        foreach($rows as $row){
             if($row['parent_id']==$parent_id){
                 $row['name_text'] = str_repeat("&nbsp;",$level*5).$row['name'];
                 $data[] = $row;
                 self::sort($rows,$row['id'],$level+1);
             }
        }
        return $data;
    }


}
